<template>
  <div class="earlyWarnHistoryWrap">
    <van-nav-bar
      title="历史预警信息"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      
    />
    <div
      class="listArea"
      v-scrollBottom="scrollBottomMet"
      infinite-scroll-distance="10"
    >
      <div
        class="listLine"
        v-for="(item, index) in listData"
        :key="Number(index)"
        @click="toDetailFile(item)"
      >
        <div class="listLeft">
          <img
            :src="
              require(`@/assets/Earlywarningmap/yujingmap/${item.imageType}-${item.degree}.png`)
            "
            alt=""
          />
        </div>
        <div class="listRight">
          <div class="listCon">
            <span>{{ item.alarmHeadline }}</span>
          </div>
          <div class="listTime">
            <span>有效日期：</span><span>{{ item.alarmEffective }}</span>
          </div>
        </div>
      </div>
      <div v-if="noData" class="noData"><span>暂无更多数据</span></div>
    </div>
    <van-popup
      v-model="showDetail"
      position="right"
      :style="{ width: '100%', height: '100%' }"
    >
      <detail
        v-if="showDetail"
        @detailBack="showDetail = false"
        :nowClickItem="nowClickItem"
        :history="history"
        @Disasterstatistics="showDetail = false"
      >
      </detail>
    </van-popup>
  </div>
</template>
<script type="text/javascript">
import meteoroDisasterWarningApi from '@/service/disasterWarning.js'
import detail from '@/components/disasterWarning/detail.vue'
export default {
  data() {
    return {
      total: 0,
      listData: [],
      page: {
        limit: 20,
        page: 1,
      },
      noData: false,
      showDetail: false,
      nowClickItem: {},
      alarmSender: '',
      history: '',
    }
  },
  mounted() {
    this.alarmSender = this.$route.params.city
    this.initApi()
  },
  watch: {},
  components: {
    detail,
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    initApi() {
      //获取当前位置
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0,
      })

      var params = {
        alarmSender: `${this.alarmSender}气象`,
        limit: this.page.limit,
        page: this.page.page,

        alarmSendtimeStart: this.$util.getTime1(),
        alarmSendtimeEnd: this.$util.getTime(),
      }
      meteoroDisasterWarningApi
        .get_tb_alarm_findByCon(params)
        .then((res) => {
          if (res.code == 0 && res.data.length != 0) {
            if (this.listData.length == 0) {
              this.listData = this.$util.getDwType(res.data)
            } else {
              var formatArr = this.$util.getDwType(res.data)
              formatArr.forEach((item) => {
                this.listData.push(item)
              })
            }
            this.total = res.total
            if (this.listData.length >= this.total) {
              this.noData = true
            }
          } else {
            this.noData = true
          }
          this.$toast.clear()
        })
        .catch((error) => {
          this.$toast.clear()
        })
    },
    scrollBottomMet() {
      if (this.noData) {
        return
      }
      //下一页
      this.page.page++
      //请求
      this.initApi()
    },
    toDetailFile(item) {
      this.nowClickItem = item
      this.history = '历史预警'
      this.showDetail = true
    },
  },
}
</script>
<style type="text/css" lang="less">
.earlyWarnHistoryWrap {
  background-color: #fff;
  .listArea {
    position: absolute;
    left: 10px;
    right: 10px;
    top: 50px;
    bottom: 10px;
    overflow-y: auto;
    background: white;
    border-radius: 10px;
    .listLine {
      overflow: hidden;
      padding: 15px 25px;
      border-bottom: 1px solid #ebedf0;
    }
    .listLeft {
      display: inline-block;
      vertical-align: middle;
      img {
        width: 30px;
      }
    }
    .listRight {
      vertical-align: middle;
      display: inline-block;
      font-size: 16px;
      margin-left: 10px;
      width: 85%;
      .listCon {
        margin-bottom: 10px;
      }
      .listTime {
        font-size: 12px;
        color: #999;
      }
    }
  }
}
</style>
